package com.tgpms.web.element.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.util.Common;
import com.tgpms.web.element.entity.ReceivingReport;
import com.tgpms.web.element.service.ReceivingReportService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(value = "ReceivingReportController", tags = "D4125 D4127 D4128验收单相关接口")
@RestController
@RequestMapping("/ev/ReceivingReport")
@Slf4j
public class ReceivingReportController {
	
	@Autowired
	private ReceivingReportService receivingReportService;

	@ApiOperation(value = "新增验收单接口", notes = "新增验收单接口", httpMethod = "POST")
    @PostMapping(value = "/addReceivingReportInfo")
    public Result addReceivingReportInfo(@RequestBody ReceivingReport en) {
		log.info("新增验收单接口接收到的对象为："+en.toString());
        Result result = new Result();
        try {
            if(Common.isEmpty(en.getMrr()) || Common.isEmpty(en.getMrrDate()) || Common.isEmpty(en.getReceivedBy())
            		|| Common.isEmpty(en.getArrivalStation()) || Common.isEmpty(en.getMrrNotes())
            		|| Common.isEmpty(en.getList()) || Common.isEmpty(en.getProject()) 
            		|| Common.isEmpty(en.getPoNo())) {
            	result.setSuccess(false);
                result.setMsg(ExceptionExplain.EMPTY_BY_DATA.getExplain());
                return result;
            }
            result = receivingReportService.addReceivingReportInfo(en);
        } catch (Exception e) {
        	e.printStackTrace();
            result.setSuccess(false);
            result.setMsg(ExceptionExplain.ERROR_BY_INSERT.getExplain());
            
        }
        return result;
    }
}
